<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'form/gform_ctrl_with_obj.class.php');

require_once('attachment_form.class.php');
require_once('attachment_form_view.class.php');

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/attachment/tcms_attachment_dbc.class.php');


class Attachment_Form_Ctrl extends GForm_Ctrl_With_Object {
	protected function create_form() {
		$form = new Attachment_Form();

//		$form->generate_html();
		return $form;
	}


	protected function create_form_view() {
		$ret = new Attachment_Form_View($this->form);

		return $ret;
	}


	protected function on_good_submit() {
		$ret = true;


		return $ret;
	}


	protected function on_bad_submit() {
		$content_id = $this->get_permanent_external_param('content', true);
		if ($content_id) {
			$this->export('attachment_cancel_link', 'admin/modules/tangra_cms/content_manage.php?manage='.$content_id);
		} else {
			$this->export('attachment_cancel_link', 'admin/modules/tangra_cms/attachment/attachments.php');
		}

		$dbc = $this->get_dbc();
		$object = $this->get_object();
		$object_id = $object->get_id();
		$attachment = new TCMS_Attachment_DBC();
		if ($attachment->load_by_id($dbc, $object_id)) {
			$this->export('orig_filename', $attachment->get_orig_filename());
		}

//		printbr('lajna');
	}


	protected function create_object() {
		$object = new TCMS_Attachment_DBC();

		return $object;
	}


	protected function transfer_obj2form() {
		$object = $this->get_object();
		$form = $this->get_form();

		$form->set_field_value('note', $object->get_note());
	}


	protected function transfer_form2obj() {
		$object = $this->get_object();
		$form = $this->get_form();

		$object->set_note($form->get_field_value('note'));
	}
}